﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OneShoppingDAL;
using OneShoppingBLL;
using OneShoppingUtility;
using OneShoppingModel;

public partial class Backstage_Pages_sysmng_menuAdd : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (role.RoleId != 1)
        {
            Response.Redirect("login.html");
        }
        if (!IsPostBack)
        {
            BindDDL();
        }
    }
    public void BindDDL()
    {
        UtilityDataBind.DropDownListBind<OneShoppingModel.Menu>(ref menulist,
            MenuBLL.GetInstance().GetList(r=>r.ParentMenu==0), "MenuName", "MenuId", "一级菜单","0");
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if(menuname.Text.Trim().Length==0)
        {
            msg_name.InnerText = "菜单名称不能为空";
            msg_name.Visible = true;
            return;
        }
        if(menuseq.Text.Trim().Length==0)
        {
            msg_seq.InnerText = "权值不能为空";
            msg_seq.Visible = true;
            return;
        }
        int mseq;
        try
        {
            mseq=Convert.ToInt32(menuseq.Text);
        }
        catch
        {
            msg_seq.InnerText = "权值必须为数字";
            msg_seq.Visible = true;
            return;
        }
        OneShoppingModel.Menu m = new OneShoppingModel.Menu
        {
            MenuName=menuname.Text,
            MenuUrl=menuurl.Text,
            MenuDispSeq = mseq,
            ParentMenu=Convert.ToInt32(menulist.SelectedValue),
            Status=1
        };
        if (m.MenuUrl.Trim().Length == 0)
            m.MenuUrl = "#";
        bool rm=MenuBLL.GetInstance().Insert(m);
        if(rm)
        {
            UtilityMessageBox.ShowAndRedirect(this,"添加成功","menuManager.aspx");
        }
        else
        {
            UtilityMessageBox.Show(this,"添加失败");
        }
    }
    protected void btnReturn_Click(object sender, EventArgs e)
    {
        Response.Redirect("menuManager.aspx");
    }
}